package com.jcn.seckill.dao;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;

import com.jcn.seckill.domain.MiaoshaOrder;
import com.jcn.seckill.domain.OrderInfo;

/**
* 添加了@Mapper注解之后这个接口在编译时会生成相应的实现类
* 需要注意的是：这个接口中不可以定义同名的方法，因为会生成相同的id
* 也就是说这个接口是不支持重载的
*/
@Mapper
public interface OrderDao {
	//sql语句
	@Select("select * from miaosha_order where user_id=#{userId} and goods_id=#{goodsId}")
	public MiaoshaOrder getMiaoshaOrderByUserIdGoodsId(@Param("userId")long userId, @Param("goodsId")long goodsId);
	//sql语句
	@Insert("insert into order_info(user_id, goods_id, goods_name, goods_count, goods_price, order_channel, status, create_date)values("
			+ "#{userId}, #{goodsId}, #{goodsName}, #{goodsCount}, #{goodsPrice}, #{orderChannel},#{status},#{createDate} )")
	@SelectKey(keyColumn="id", keyProperty="id", resultType=long.class, before=false, statement="select last_insert_id()")
	public long insert(OrderInfo orderInfo);
	//sql语句
	@Insert("insert into miaosha_order (user_id, goods_id, order_id)values(#{userId}, #{goodsId}, #{orderId})")
	public int insertMiaoshaOrder(MiaoshaOrder miaoshaOrder);
	//sql语句
	@Select("select * from order_info where id = #{orderId}")
	public OrderInfo getOrderById(@Param("orderId")long orderId);
	//sql语句
	@Delete("delete from order_info")
	public void deleteOrders();
	//sql语句
	@Delete("delete from miaosha_order")
	public void deleteMiaoshaOrders();

	
}
